home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / READ.C < prev    next >
Encoding:
Text File  |  1991-08-05  |  605 b   |  24 lines

  1. /* read.c --- p 502 */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. static char bigbuffer[60000];
  6. main()
  7. {
  8.     int fhandle;
  9.     int bytes_read;
  10.         /* Open the file "autoexec.bat." Note that we need two '\' */
  11.     if ( (fhandle = open("c:autoexec.bat", O_RDONLY)) == -1)
  12.     {
  13.         printf("open failed");
  14.         exit(1);
  15.     }
  16.     printf("Attempting to read 60000 bytes from c:autoexec.bat:\n");
  17.     if ((bytes_read = read(fhandle, bigbuffer, 60000)) == -1)
  18.     {
  19.         perror("read error");
  20.         exit(1);
  21.      }
  22.     printf("only %u bytes read. Here's what was read:\n", bytes_read);
  23.     write(1, bigbuffer, bytes_read);
  24. }